<style lang="less">
  .filltitle {
    text-align: center;
    line-height: 28px;
    margin-bottom: 20px;
    dt {
      font-size: 16px;
    }
    dd {
      font-size: 12px;
      color: #888;
    }
  }

  .login-wrap {
    padding: 0 0.3rem;
  }
</style>
<template>
  <div class="contain">
    <div class="loader-base" v-if="showLoad">
      <div class="loader-wrap"></div>
    </div>
    <img src="@/assets/bg/pc_head.png" style="width:100%">
    <div class="filltitle">
      <dl>
        <dt>请填写您的信息</dt>
        <dd>此信息为唯一凭证，请确保无误</dd>
      </dl>
    </div>
    <ul class="login-wrap">
      <li class="displayflex">
        <span class="iconfont icon-account"></span>
        <div class="flex1 login-ipt"><input type="text" placeholder="姓名" v-model.trim="name" maxlength="4"></div>
        <span class="iconfont icon-del" v-if="name" @click="name=''"></span>
      </li>

      <li class="displayflex">
        <span class="iconfont icon-school"></span>
        <div class="flex1 login-ipt"><input placeholder="所属机构" v-model.trim="school"></div>
        <span class="iconfont icon-del" v-if="school" @click="school=''"></span>
      </li>

      <div class="agbtn btn-info" style="display:block; height:45px; line-height:45px;"
           @click="goNext">
        确认并继续
      </div>
    </ul>
  </div>

</template>

<script>
  export default {
    data() {
      return {
        showLoad: false,
        name: '',
        school: '',

      }
    },
    computed: {
      WxOpenId() {
        if (localStorage.WeChatOpenId) {
          return localStorage.WeChatOpenId;
        }
      }
    },
    methods: {
      goNext() {
        if (this.name === "") {
          this.$vux.toast.show({
            type: "warn", //success, warn, cancel, text
            text: "请填写姓名"
          });
          return false;
        }
        this.jumpToNext();
      },
      getOpenid() {
        let self = this;
        if (this.WxOpenId && this.WxOpenId !== '') {
          self.jumpToNext();
        }
        else {
          let query = {
            Code: self.$route.query.code,
          };
          this.showLoad = true;
          this.Ajax.post("GetOpenId", query).then(function (resp) {
            self.showLoad = false;
            if (resp.IsSuccess) {
              localStorage.WeChatOpenId = resp.Data.openid;
              sessionStorage.clear();
            }
            else {
              self.$vux.toast.show({
                type: "warn", //success, warn, cancel, text
                text: "用户信息失效，重新登录中...",
                onHide() {
                  window.location.href = 'http://wx.yilaibaobei.com/orgRegister.html';
                }
              });
            }
          });
        }
      },
      jumpToNext() {
        let self = this;
        let query = {
          name: this.name,
          school: this.school,
          openid: this.WxOpenId
        };
        self.Ajax.post("GetCode", query).then(function (resp) {
          let code = resp.code;
          self.$router.push({
            path: 'CreateQrCode',
            query: {
              code: code
            }
          })
        });

      }
    },
    created() {
      this.getOpenid();
    }
  }
</script>

